package jp.melodroid.no5.scroll3;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LayoutTest extends Activity implements View.OnClickListener
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);

	LinearLayout ll = (LinearLayout)findViewById(R.id.features);
	int childMax = ll.getChildCount();
	for (int count=0;count < childMax;count++) {
	    View v = ll.getChildAt(count);
	    if (v instanceof Button) {
		v.setOnClickListener(this);
	    }
	}

	Button b = (Button)findViewById(R.id.button_ok);
	b.setOnClickListener(new View.OnClickListener() {
		public void onClick(View v) {
		    EditText e = (EditText)findViewById(R.id.edit);
		    String s = e.getText().toString();
		    if (s.equals("")) {
			s = getResources().getString(R.string.button_ok);
		    }
		    Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
		}
	    });

	b = (Button)findViewById(R.id.button_ng);
	b.setOnClickListener(new View.OnClickListener() {
		public void onClick(View v) {
		    String s = getResources().getString(R.string.button_ng);
		    Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
		}
	    });
    }

    public void onClick(View v) {
	if (!(v instanceof Button)) {
	    return;
	}

	Button button = (Button)v;
	String s = button.getText().toString();

	EditText e = (EditText)findViewById(R.id.edit);
	e.setText(s, TextView.BufferType.NORMAL);
    }
}
